package com.oplink.webems.common.utils;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.oplink.webems.modules.alarm.entity.AlarmCurrent;
import com.oplink.webems.modules.cfg.entity.CfgNe;
import com.oplink.webems.modules.cfg.entity.CfgSite;

public class AlarmUtils {
	public final static int HIGHEST_LEVEL = 10;
	
	public static TreeMap<Integer, Integer> getAllAlarmCount(List<CfgSite> list){
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		
		for(CfgSite site : list){
			Map<Integer, Integer> _map = getSiteAlarmCount(site);
			for(Integer key : _map.keySet()){
				if(map.get(key) == null){
					map.put(key, 0);
				}
				map.put(key, map.get(key)+_map.get(key));
			}
		}
		return map;
	}
	
	public static TreeMap<Integer, Integer> getSiteAlarmCount(CfgSite site){
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		
		List<CfgNe> list = site.getNelist();
		
		for(CfgNe ne : list){
			Map<Integer, Integer> _map = getCfgNeAlarmCount(ne);
			for(Integer key : _map.keySet()){
				if(map.get(key) == null){
					map.put(key, 0);
				}
				map.put(key, map.get(key)+_map.get(key));
			}

		}
		
		return map;
	}
	
	public static TreeMap<Integer, Integer> getCfgNeAlarmCount(CfgNe ne){
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		
		List<AlarmCurrent> list = ne.getAcurlist();
		
		for(AlarmCurrent a : list){
			int alarmLevel = a.getSeverity().getId().intValue();
			if(alarmLevel == HIGHEST_LEVEL){//不管数据库规定最高告警是多少，这里统一指定为-1
				alarmLevel = -1;
			}
			if(map.get(alarmLevel) == null){
				map.put(alarmLevel, 0);
			}
			map.put(alarmLevel, map.get(alarmLevel)+1);
		}
		
		return map;
	}
	
}
